package com.company.test;

import java.util.ArrayList;

public class SubSet1 {

    public int getSum1(boolean[] visited, int[] A) {
        int sum = 0;
        for (int i = 0; i < A.length; i++) {
            if (visited[i])
                sum += A[i];
        }
        return sum;
    }

    public void getSubSet1(boolean[] visited, int[] A, int m, int step) {
        if (step == A.length) {
            if (getSum1(visited, A) == m) {
                for (int i = 0; i < A.length; i++) {
                    if (visited[i])
                        System.out.print(A[i] + " ");
                }
                System.out.println();
            }
            return;
        }
        visited[step] = true;
        getSubSet1(visited, A, m, step + 1);
        visited[step] = false;
        getSubSet1(visited, A, m, step + 1);
    }

    public static void main(String[] args) {
        SubSet1 test = new SubSet1();
        int[] A  = {5, 4, 6};
        boolean[] visited = new boolean[3];
        for (int i = 0; i < 3; i++) {
            visited[i] = false;
        }
        test.getSubSet1(visited, A, 10, 0);
    }
}